﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter
{
    public class PrinterData
    {
        public class Printer
        {
            public static List<Printer> Printers = new List<Printer>();

            public Printer(string clientID, string printerName)
            {
                this.ClientID = clientID;
                this.PrinterName = printerName;
            }

            public string ClientID
            {
                get;
                set;
            }

            public string PrinterName
            {
                get;
                set;
            }

            public override bool Equals(object obj)
            {
                if (obj is Printer)
                {
                    Printer printer = obj as Printer;
                    return this.ClientID.Equals(printer.ClientID) 
                        && this.PrinterName.Equals(printer.PrinterName);
                }
                return false;
            }
        }


        public void SavePrinters(List<string> printers, string clientID)
        {
            foreach (string p in printers)
            {
                bool existed = false;
                Printer.Printers.ForEach(_p =>
                {
                    if (_p.ClientID.Equals(clientID) 
                        && _p.PrinterName.Equals(p))
                    {
                        existed = true;
                    }
                        
                });
                if (!existed)
                {
                    Printer.Printers.Add(new Printer(clientID, p));
                }
            }
        }

        public List<Printer> GetPrinters()
        {
            return Printer.Printers ?? new List<Printer>();
        }
    }
}
